import uuid
from djangomodel.modelclass import StrField
from django.db import models

# Create your models here.

## 组织信息 名称、电话、地址
class OrgModel(models.Model):
    name = StrField(max_length=100)
    phone = StrField(max_length=20,null=True,blank=True)
    email = models.EmailField(null=True,blank=True)
    address = StrField(max_length=300,null=True,blank=True)
    class Meta:
        db_table = "pj_org"


## 部门模型    uuid、名称、上级部门
class DepartmentModel(models.Model):
    uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = StrField(max_length=100,unique=True)
    administration = models.ForeignKey("org.DepartmentModel",on_delete=models.SET_NULL,null=True,blank=True)
    class Meta:
        db_table = "pj_department"

## 角色模型
class RoleModel(models.Model):
    uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = StrField(max_length=100,unique=True)
    notes = models.TextField(null=True,blank=True)
    class Meta:
        db_table = "pj_role"

## 用户模型
class UserModel(models.Model):
    uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user_id = StrField(max_length=100,null=True,blank=True)
    username = StrField(max_length=100,unique=True)
    name = StrField(max_length=100)
    passwd = StrField(max_length=100)
    department = models.ForeignKey("org.DepartmentModel",on_delete=models.SET_NULL,null=True,blank=True)
    phone = StrField(max_length=11,null=True,blank=True)
    email = StrField(max_length=100,null=True,blank=True)
    enable = models.BooleanField(default=True)
    roles = models.ManyToManyField(RoleModel,blank=True)
    class Meta:
        db_table = "pj_user"

